﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.ServiceModel;
using System.Runtime.Serialization;

namespace WcfService
{
    [ServiceContract(Name = "Operate")]
    public interface IOperate<T>
    {
        [OperationContract]
        bool Insert(IList<T> listObj);

        [OperationContract]
        bool Update(IList<T> listObj);

        [OperationContract]
        bool Delete(params int[] i);

        [OperationContract]
        IList<T> Select();
    }

    [DataContract]
    public class UserAccount
    {
        [DataMember]
        public string UserName { get; set; }

        [DataMember]
        public string LoginIP { get; set; }

        [DataMember]
        public string LoginData { get; set; }
    }

    [ServiceContract]
    public interface IOperateUseAccount : IOperate<UserAccount>
    {
        [OperationContract]
        void X();
    }
    // 单例服务(Singleton Service)
    // 宿主程序启动的时候就已经初始化好服务实例
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
    public class OperateUseAccount : IOperateUseAccount
    {
        public OperateUseAccount()
        {
            Console.WriteLine("Single Create...");
        }

        #region IOperate<UserAccount> 成员

        public bool Insert(IList<UserAccount> listObj)
        {
            Console.WriteLine("Insert common!");
            foreach (UserAccount item in listObj)
            {
                Console.WriteLine(System.Environment.NewLine + "UserName={0}-LoginIP={1}-LoginData={2} ", item.UserName, item.LoginIP, item.LoginData);
            }
            return true;
        }

        public bool Update(IList<UserAccount> listObj)
        {
            Console.WriteLine("Update common!");
            foreach (UserAccount item in listObj)
            {
                Console.WriteLine(System.Environment.NewLine + "UserName={0}-LoginIP={1}-LoginData={2} ", item.UserName, item.LoginIP, item.LoginData);
            }
            return true;
        }

        public bool Delete(params int[] i)
        {
            Console.WriteLine("Delete common!");
            return false;
        }

        public IList<UserAccount> Select()
        {
            return null;
        }
        public void X() { }

        #endregion
    }
}
